package com.hyfrogx.modules.information.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.modules.information.entity.InfoCommentEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author liubin
 * @date 2019/11/1 10:43
 */
@Mapper
public interface InfoCommentDao extends BaseMapper<InfoCommentEntity> {

  /**
   * 取这条资讯的所有评论
   * @param infoId
   * @return
   */
  @Select("SELECT\n" +
    "\t\ti.to_uid as touid,i.pid,i.id,i.info_id AS infoId,i.uid,i.comment,i.comment_time AS\n" +
    "\t\tcommentTime,i.state,u.username AS username\n" +
    "\t\tfrom\n" +
    "\t\thy_info_comment i\n" +
    "\t\tleft\n" +
    "\t\tjoin hy_user u\n" +
    "\t\ton u.uid=i.uid\n" +
    "\t\twhere\n" +
    "\t\t\tpid=0\n" +
    "\t\t\tand info_id = #{infoId}\n" +
    "\t\t\tand i.state=1\n" +
    "\t\tORDER BY comment_time desc")
  List<InfoCommentEntity> getInformationCommentforApi(@Param("infoId") Integer infoId);

  /**
   * 取这条评论的所有回复
   * @param id
   * @return
   */
  @Select("SELECT\n" +
    "\t\ti.to_uid as touid,i.pid,i.id,i.info_id AS infoId,i.uid,i.comment,i.comment_time AS\n" +
    "\t\tcommentTime,i.state,u.username AS username\n" +
    "\t\tfrom\n" +
    "\t\thy_info_comment i\n" +
    "\t\tleft\n" +
    "\t\tjoin hy_user u\n" +
    "\t\ton u.uid=i.uid\n" +
    "\t\twhere\n" +
    "\t\t\tpid !=0\n" +
    "\t\t\tand pid = #{id}\n" +
    "\t\tORDER BY comment_time desc")
  List<InfoCommentEntity> getCommentReplyforApi(@Param("id") Integer id);

  @Select("SELECT\n" +
    "\t\tu.phone,c.id,c.info_id AS\n" +
    "\t\tinfoId,c.uid,c.comment,c.comment_time AS\n" +
    "\t\tcommentTime,c.state\n" +
    "\t\tfrom\n" +
    "\t    hy_info_comment c\n" +
    "\t    left join hy_user u on u.uid=c.uid\n" +
    "\t\twhere\t\t\n" +
    "\t\tc.pid = #{page.id,jdbcType=INTEGER}\t\t\t\n" +
    "\t\tand c.uid = #{map.replyuid,jdbcType=INTEGER}\n" +
    "\t\tand c.to_uid = #{map.uid,jdbcType=INTEGER}\t\t\t\n" +
    "\t\tORDER BY c.comment_time DESC")
  List<InfoCommentEntity> getReplyCommentsByUid(QueryExt query, @Param("map")Map map);

  @Select("SELECT\n" +
    "\t\tu.phone,c.id,c.info_id AS\n" +
    "\t\tinfoId,c.uid,c.comment,c.comment_time AS\n" +
    "\t\tcommentTime,c.state\n" +
    "\t\tfrom\n" +
    "\t    hy_info_comment c\n" +
    "\t    left join hy_user u on u.uid=c.uid\n" +
    "\t\twhere\t\t\n" +
    "\t\tc.pid = #{map.id,jdbcType=INTEGER}\t\t\t\n" +
    "\t\t\t\t\t\n" +
    "\t\tORDER BY c.comment_time DESC")
  List<InfoCommentEntity> getAllReplyComments(QueryExt query, @Param("map") Map map);

  List<InfoCommentEntity> getOldInformationComments(QueryExt queryExt, @Param("map") Map map);

  List<InfoCommentEntity> getAllInformationComment(QueryExt queryExt, @Param("map") Map map);
}
